/**
 * 
 */
package com.admissions.data;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.admissions.common.Constants;
import com.admissions.model.DapAnMonThiModel;
import com.admissions.model.DepartmentModel;
import com.admissions.model.ExamModel;
import com.admissions.model.TruongModel;

/**
 * @author LongNH
 * 
 */
public class DataPaser implements Constants {
	public static List<ExamModel> getListKhoiThiCoDapAn(String content) {
		List<ExamModel> listExam = new ArrayList<ExamModel>();
		try {
			JSONObject json = new JSONObject(content);
			JSONObject response = json.getJSONObject("response");
			String status = response.getString("status");

			if (RESULT_TRUE.equals(status)) {
				JSONObject result = response.getJSONObject("result");
				JSONArray earthquakes = result.getJSONArray("khoi");
				int length = earthquakes.length();

				for (int i = 0; i < length; i++) {
					JSONObject e = earthquakes.getJSONObject(i);
					ExamModel object = new ExamModel();

					String id = e.getString("id");
					String name = e.getString("name");

					object.setId(id);
					object.setName(name);

					listExam.add(object);

				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		} catch (NullPointerException e) {

		}

		return listExam;
	}

	public static List<DepartmentModel> getListMonThiCoDapAn(String content) {
		List<DepartmentModel> listDepartment = new ArrayList<DepartmentModel>();
		try {
			JSONObject json = new JSONObject(content);
			JSONObject response = json.getJSONObject("response");
			String status = response.getString("status");

			if (RESULT_TRUE.equals(status)) {
				JSONObject result = response.getJSONObject("result");
				JSONArray earthquakes = result.getJSONArray("monthi");
				int length = earthquakes.length();

				for (int i = 0; i < length; i++) {
					JSONObject e = earthquakes.getJSONObject(i);
					DepartmentModel object = new DepartmentModel();

					String id = e.getString("id");
					String name = e.getString("name");

					object.setId(id);
					object.setName(name);

					listDepartment.add(object);

				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		} catch (NullPointerException e) {

		}

		return listDepartment;
	}

	public static List<DapAnMonThiModel> getListDapAnCuaMonThi(String content) {
		List<DapAnMonThiModel> listAnswer = new ArrayList<DapAnMonThiModel>();
		try {
			JSONObject json = new JSONObject(content);
			JSONObject response = json.getJSONObject("response");
			String status = response.getString("status");

			if (RESULT_TRUE.equals(status)) {
				JSONObject result = response.getJSONObject("result");
				JSONArray earthquakes = result.getJSONArray("dapan");
				int length = earthquakes.length();

				for (int i = 0; i < length; i++) {
					JSONObject e = earthquakes.getJSONObject(i);
					DapAnMonThiModel object = new DapAnMonThiModel();

					String dapAnDung = e.getString("dapandung");
					String name = e.getString("name");

					object.setDapAnDung(dapAnDung);
					object.setName(name);

					listAnswer.add(object);

				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		} catch (NullPointerException e) {

		}

		return listAnswer;
	}

	public static List<TruongModel> getListTruongCoTyLeChoi(String content) {
		List<TruongModel> listTruong = new ArrayList<TruongModel>();
		try {
			JSONObject json = new JSONObject(content);
			JSONObject response = json.getJSONObject("response");
			String status = response.getString("status");

			if (RESULT_TRUE.equals(status)) {
				JSONObject result = response.getJSONObject("result");
				JSONArray earthquakes = result.getJSONArray("truong");
				int length = earthquakes.length();

				for (int i = 0; i < length; i++) {
					JSONObject e = earthquakes.getJSONObject(i);
					TruongModel object = new TruongModel();

					String id = e.getString("id");
					String name = e.getString("name");

					object.setId(id);
					object.setName(name);

					listTruong.add(object);

				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		} catch (NullPointerException e) {

		}

		return listTruong;
	}

	public static String getTyLeChoi(String content) {
		String contentTyLeChoi = "";
		try {
			JSONObject json = new JSONObject(content);
			JSONObject response = json.getJSONObject("response");
			String status = response.getString("status");

			if (RESULT_TRUE.equals(status)) {
				JSONObject result = response.getJSONObject("result");
				JSONObject tyLeChoi = result.getJSONObject("tylechoi");
				contentTyLeChoi = tyLeChoi.getString("tylechoi");
				
			}
		} catch (JSONException e) {
			e.printStackTrace();
		} catch (NullPointerException e) {

		}

		return contentTyLeChoi;
	}
}
